<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style>
            .error{color:blueviolet}
            .nen{background: yellow}
        </style>
    </head>
    <body class=nen>
        <?php

        function test_input($data) {
            return $data;
        }

        function test_input1($data) {
            return strtoupper($data);
        }
        function test_input2($data){
            return '<b>'.strtoupper($data).'</b>';
        }
        function test_input3($data){
            return '<font size="25">'.$data.'</font>';
        }

        //define variables and set to empty values
        $nameErr = $emailErr = $genderErr = $websiteErr = "";
        $name = $email = $gender = $comment = $website = "";
        if ($_SERVER["REQUEST_METHOD"] == "POST") {
            if (empty($_POST["name"])) {
                $nameErr = " Moi ban hay nhap ten";
            } else {
                $name = test_input1($_POST["name"]);
            }
            if (empty($_POST["email"])) {
                $emailErr = "Ban hay nhap dia chi email";
            } else {
                $email = test_input2($_POST["email"]);
            }
            if (empty($_POST["website"])) {
                $websiteErr = "ban hay nhap website vao ";
            } else {
                $website = test_input($_POST["website"]);
            }
            if (empty($_POST["comment"])) {
                $comment = "";
            } else {
                $comment = test_input3($_POST["comment"]);
            }
            if (empty($_POST["gender"])) {
                $genderErr = "Ban hay lua chon gioi tinh ";
            } else {
                $gender = test_input($_POST["gender"]);
            }
        }
        ?>
        <h2>PHP Form validation Example </h2>
        <p><span class="error">* request field.</span></p>
        <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
            Name: <input type="text" name="name" value="<?php echo $name; ?>">
            <span class="error">*<?php echo $nameErr; ?></span>
            <br> <br>
            Email:<input type="text" name="email" value="<?php echo $email; ?>">
            <span class="error">*<?php echo $emailErr; ?></span>
            <br> <br>
            Website:<input type="text" name="website" value="<?php echo $website; ?>">
            <span class="error">*<?php echo $websiteErr; ?></span>
            <br> <br>
            Comment : <textarea name="comment" rows="10" cols="50"><?php echo $comment; ?></textarea>
            <br> <br>
            Gender : 
            <input type="radio" name="gender" <?php if (isset($gender) && $gender == "female") echo "checked"; ?> value="female">Female
            <input type="radio" name="gender" <?php if (isset($gender) && $gender == "male") echo "checked"; ?> value="male"> Male
            <span class="error">*<?php echo $genderErr; ?></span>
            <br> <br>
            <input type="submit" name="submit" value="Gui"> 
        </form>
        <?php
        echo $name . '<br>';
        echo $email . '<br>';
        echo $website . '<br>';
        echo $comment . '<br>';
        echo $gender . '<br>';
        ?>
    </body>
</html>
